<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>表格查询</title>
    <#assign base=request.contextPath  />
    <base id="base" href="${base}">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, adminUser-scalable=0">
    <link rel="stylesheet" href="${base}/static/win10/component/layui/css/layui.css" media="all">
    <script>
        var base =  "${base}";
    </script>
</head>
<body>
<br>


<div class="demoTable" style="margin-left: 15px;">
    <form class="layui-form " action="" >
    <div class="layui-form-item">
        <label>企业名字</label>
        <div class="layui-inline">
            <input class="layui-input" name="companyName" id="companyName" autocomplete="off">
        </div>

        <button type="button" class="layui-btn" data-type="reload">
            <i class="layui-icon layui-icon-search">搜索</i>
        </button>
    </div>
    </form>
</div>
<table class="layui-hide" id="test" lay-filter="test"></table>
<script type="text/html" id="toolbarDemo">


    <form class="layui-form " action="">
        <div class="layui-form-item" style="margin-left: 15px;">
            <div class="layui-btn-group">
                <button type="button" class="layui-btn" lay-event="add">增加</button>
                <button type="button" class="layui-btn" lay-event="edit">编辑</button>
                <button type="button" class="layui-btn" lay-event="show">查看</button>
                <button type="button" class="layui-btn" lay-event="del">删除</button>
            </div>
        </div>

    </form>
</script>

<script src="${base}/static/win10/component/layui/layui.js?t=1"></script>
<script src="${base}/static/win10/js/jquery-1.8.3.min.js?t=1"></script>
<script>
    layui.use(['table'], function () {
        var table = layui.table;
        table.render({
            skin: 'line' //行边框风格
            , even: true //开启隔行背景
            , elem: '#test'
            , url: base + '/WeChatUser/wechatCompany/admin/findWechatCompanyByPage'
            , toolbar: '#toolbarDemo'
            , cols: [[
                {type: 'radio'},
                  {field: 'companyId', title: '企业ID'},
                  {field: 'companyName', title: '企业名字'},
                  {field: 'companyQualification', event: 'companyQualification',title: '企业资质验证'},
                  {field: 'companyLicenseImg',event: 'companyLicenseImg', title: '营业执照图片'},
                  {field: 'userId', title: '关联用户'},
                  /*{field: 'createTime', title: '创建时间'},
                  {field: 'updateTime', title: '修改时间'},*/
                  {field: 'companyIsDelete', title: '是否正常', templet: function (d) {
                        return d.companyIsDelete==0 ? "正常" : "删除"
                      }
                   },
                  /*{field: 'companyRemarks', title: '企业备注'},*/
                  {field: 'areaId', title: '企业区域 ',templet: function (d) {
                          return getAreaName(d.areaId);
                      }
                  },
                  {field: 'companyScale', title: '企业规模'},
                  {field: 'companyLogo',event: 'companyLogo', title: '企业Logo'}
            ]]
            , page: true
            , id: 'testReload'
        });
        //搜索
        var $ = layui.$, active = {
            reload: function(){
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                                    companyName:$("#companyName").val(),
                                    companyQualification:$("#companyQualification").val(),
                                    companyLicenseImg:$("#companyLicenseImg").val(),
                                    userId:$("#userId").val(),
                                    companyIsDelete:$("#companyIsDelete").val(),
                                    companyRemarks:$("#companyRemarks").val(),
                                    areaId:$("#areaId").val(),
                                    companyScale:$("#companyScale").val(),
                                    companyLogo:$("#companyLogo").val()
                    }
                }, 'data');
            }
        };
        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
            var data = checkStatus.data;  //获取选中行数据
            switch (obj.event) {
                case 'add':
                    //请继续补充以下逻辑
                    window.location.href=base+"/WeChatUser/wechatCompany/admin/addWechatCompanyHtml"
                    break;
                case 'edit':
                    if (data.length === 0) {
                        layer.alert("请选择一条数据")
                        return;
                    }
                    //请继续补充以下逻辑
                    window.location.href=base+"/WeChatUser/wechatCompany/admin/editWechatCompanyHtml?id=" + data[0].companyId
                    break;
                case 'show':
                    if (data.length === 0) {
                        layer.alert("请选择一条数据")
                        return;
                    }
                    //请继续补充以下逻辑
                    window.location.href=base+"/WeChatUser/wechatCompany/admin/showWechatCompanyHtml?id=" + data[0].companyId
                    break;
                case 'del':
                    if (data.length === 0) {
                        layer.alert("请选择一条数据")
                        return;
                    }
                    layer.confirm('真的要删除吗?',function(index){
                        $.ajax({
                            type:"POST",
                            url:base+'/WeChatUser/wechatCompany/admin/delWechatCompany',
                            data:{"id":data[0].companyId},
                            success:function(data){
                                if(data.code===200){
                                    layer.msg(data.message)
                                    setTimeout(function () {
                                        window.location.reload();
                                    }, 500)
                                }else{
                                    layer.msg(data.message)
                                }
                            }
                        });
                    });
                    break;
            };
        });

        //监听单元格事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            //console.log(data);
            if (obj.event=="companyQualification"){
                PreviewImg(data.companyQualification);
            }
            if (obj.event=="companyLicenseImg"){
                PreviewImg(data.companyLicenseImg);
            }
            if (obj.event=="companyLogo"){
                PreviewImg(data.companyLogo);
            }
        });

    })

    function PreviewImg(value) {
        layui.use('layer', function () {
            var layer = layui.layer;
            var height = $(document).height()*0.8; //获取图片高度
            var width = $(document).width()*0.9; //获取图片宽度
            var imgHtml = "<img src='" + value + "' />";
            layer.open({
                type: 1,
                shade: 0.8,
                offset: 'auto',
                area: [width + 'px',height+'px'],
                shadeClose:true,//点击外围关闭弹窗
                scrollbar: false,//不现实滚动条
                title: false, //不显示标题
                content: imgHtml, //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
                cancel: function () {
                    //layer.msg('捕获就是从页面已经存在的元素上，包裹layer的结构', { time: 5000, icon: 6 });
                }
            });
        });

    }
    function getAreaName(value) {
        var str ;
        $.ajax({
            type:"POST",
            async: false,
            url:base+'/WeChatUser/wechatArea/admin/getAreaName',
            data:{"areas" : value},
            success:function(data){
                str = data;
            }
        });
        return str;
    }
</script>
</body>
</html>